﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _2012_3_Indices
{
    class Indices
    {
        /*
         * You are given a zero-based array ARR with N integer numbers in it. Each element of ARR is an index in the ARR (seems like a recursive definition, right?).
         * You are also given the sequence that starts from the first element (0) then moves to the element with index ARR[0], 
         * then moves to the element with index ARR[ARR[0]], 
         * then moves to the element with index ARR[ARR[ARR[0]]], and so on…
         * The full sequence is generated by performing these actions until you reach an index that is outside the bounds of the array ARR. 
         * Of course cycles are absolutely possible. When a cycle is started in the sequence it may never reach any index that is outside the bounds of the ARR.
         * Write a program that outputs the elements in the given sequence. When you find cycle you should output it in round brackets as shown in the examples below. 
         * Please note that no spaces should be printed between the brackets and the number.
         *Input
         * The input data should be read from the console.
         * In the first input line you are given the number N of the elements in ARR.
         * From the second line you should read the numbers in the array ARR separated by a single space.
         * The input data will always be valid and in the format described. There is no need to check it explicitly.
         *Output
         * The output data should be printed on the console.
         * On the only output line you should print the described sequence. 
         * All the cycles should be printed with round brackets, with no spaces between the brackets and the numbers.
        */

        static int[] array;
        static int[] trace;

        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string[] input = Console.ReadLine().Split(" ".ToCharArray());
            array = new int[n];
            trace = new int[n];

            for (int i = 0; i < input.Length; i++)
            {
                array[i] = int.Parse(input[i]);
                trace[i] = -1;
            }

            Go(0);

        }

        static void Go(int index)
        {
            int nextIndex = array[index];

            if (nextIndex >= array.Length)
            {
                int backtrace = trace[index];
                StringBuilder sb = new StringBuilder();
                sb.Append(index);
                while (backtrace != 0)
                {
                    sb.Append(backtrace);
                    backtrace = trace[backtrace];
                }
                sb.Append(backtrace);
                PrintSequence(sb);
                return;

            }
            else if (trace[nextIndex] > -1)
            {
                //cycle; backtrace
                int backtrace = trace[index];
                StringBuilder sb = new StringBuilder();
                sb.Append(")");
                sb.Append(index);
                while (backtrace != 0)
                {
                    sb.Append(backtrace);
                    if (backtrace == nextIndex)
                    {
                        sb.Append("(");
                    }
                    backtrace = trace[backtrace];
                }
                sb.Append(backtrace);
                PrintSequence(sb);
                return;
            }
            else
            {
                trace[nextIndex] = index;
                Go(nextIndex);
            }

        }

        private static void PrintSequence(StringBuilder sb)
        {
            char[] rev = sb.ToString().ToCharArray();
            Array.Reverse(rev);
            String result = new String(rev);
            Console.WriteLine(result);
        }

    }
}
